package com.gitee.mazhenggg.demo.auth.service;

import com.gitee.mazhenggg.demo.auth.entity.Role;
import com.gitee.mazhenggg.demo.auth.entity.SysUser;
import com.gitee.mazhenggg.demo.auth.rpc.UserClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Set;

@Service
public class UserService {

    @Autowired
    UserClient userClient;

    public SysUser getUserByName(String name){
        SysUser sysUser = userClient.info(name);
//        SysUser sysUser = new SysUser();
//        sysUser.setUsername("aaa");
//        sysUser.setPassword(new BCryptPasswordEncoder().encode("bbb"));
//
//        //sysUser.setPassword("bbb");
        sysUser.setPassword(new BCryptPasswordEncoder().encode(sysUser.getPassword()));
        Role r = new Role();
        r.setCode("1");
        Set<Role> s = new HashSet<>();
        s.add(r);
        sysUser.setRoles(s);
        return sysUser;
    }
}
